<?php
namespace app\controller;

use app\BaseController;
use liliuwei\think\Auth;
use think\facade\Db;
use think\facade\Session;
class Log extends BaseController
{
    protected $gobaluser=0;
    protected $getpath="";
    public function __construct(){
        checkuser();
        $this->getpath=strtolower(request()->controller())."/".strtolower(request()->action());
        $this->gobaluser=Session::get("uid");
    }
    public function list()
    {
        return view("log/index");
    }
    public function info(){
        $id=request()->param("id");
        $re=DB::name("log")->where("id",$id)->find();
        if($re){
            echojson([],0,$re['content']);
        }else{
            echojson([],1,"id错误:");
        }
    }
    public function loglist(){
        $uid=request()->param("uid");
        $date1=request()->param("date1");
        $date2=request()->param("date2");
        $limit=request()->param("limit");
        $page=request()->param("page");
        $date1=date("Y-m-d",strtotime($date1));
        $date2=date("Y-m-d",strtotime($date2));
        $sql=DB::name("log")->alias("a")->field("a.*,b.fullname")->leftJoin("admin b","a.uid=b.id");
        if($uid>0){$sql=$sql->where("b.uid",$uid);}
        if(($date1 || $date2) && $date1<$date2){
            $sql=$sql->where("addtime",">=",$date1)->where("addtime","<=",$date2);
        }
        $sql2=clone $sql;
        $count=$sql2->count();
        $page=$page>ceil($count/$limit)?$count:$page;
        $page=$page<1?1:$page;
        $lists=$sql->limit((($page-1)*$limit),$limit)->order("a.id desc")->select();
        pagejson($lists,0,"",$count);
    }
}
